package top.yokey.shopai.zcom.adapter;

import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.viewpager.widget.PagerAdapter;

import java.util.List;

@SuppressWarnings("ALL")
public class ViewPagerAdapter extends PagerAdapter {

    private List<View> viewList = null;
    private List<String> titleList = null;

    public ViewPagerAdapter(List<View> viewList, List<String> titleList) {

        this.viewList = viewList;
        this.titleList = titleList;

    }

    @Override
    public int getCount() {

        return viewList.size();

    }

    @Override
    public boolean isViewFromObject(@NonNull View view, @NonNull Object object) {

        return view == object;

    }

    @NonNull
    @Override
    public Object instantiateItem(@NonNull ViewGroup viewGroup, int position) {

        viewGroup.addView(viewList.get(position));
        return viewList.get(position);

    }

    @Override
    public void destroyItem(@NonNull ViewGroup viewGroup, int position, @NonNull Object object) {

        viewGroup.removeView(viewList.get(position));

    }

    @Override
    public CharSequence getPageTitle(int position) {

        return titleList.get(position);

    }

}
